<template>
  <div>
    <custom-title :is-line="true" title="企业环保信息" />
    <div class="qyhbxx">
      <div v-for="(item, index) in descList" :key="index + 'base'">
        <custom-details-item :icon="item.icon" :label="item.label">
          <template #valueSlot>
            <span v-if="!item.isFile">{{ item.value }}</span>
            <template v-else>
              <el-link type="primary" @click="openAttachPopUp(item.value)">查看</el-link>
            </template>
          </template>
        </custom-details-item>
      </div>
    </div>
    <!--    <custom-title :is-line="true" title="企业纳入国家环境信用评价情况" />-->
    <custom-title :is-line="true" title="企业信用评价" />
    <div class="qyxypj">
      <div v-for="(item, index) in descList1" :key="index + 'all'">
        <custom-details-item :icon="item.icon" :label="item.label" :value="item.value + ''">
          <template #valueSlot>
            <span v-if="!item.isFile">{{ item.value }}</span>
            <template v-else>
              <el-link type="primary" @click="openAttachPopUp(item.value)">查看</el-link>
            </template>
          </template>
        </custom-details-item>
      </div>
    </div>
    <custom-title :is-line="true" title="企业排污许可" />
    <div class="qypwxk">
      <div v-for="(item, index) in descList2" :key="index + 'info'">
        <custom-details-item :icon="item.icon" :label="item.label" :value="item.value + ''" />
      </div>
    </div>
    <attachPopUp ref="attachPopUp" />
  </div>
</template>

<script>
import commonList from '@/assets/mixin/commonList'
import { companyInfoEnvironment } from '@/api/enterprise'
import CustomDetailsItem from '@/components/globals/custom-details-item.vue'
import CustomTitle from '@/components/globals/custom-title.vue'

export default {
  name: 'EnviromentComponent',
  components: { CustomTitle, CustomDetailsItem },
  mixins: [commonList],
  props: {
    companyId: {
      type: [String, Number],
      default: ''
    }
  },
  data() {
    return {
      descList: [
        {
          label: '集团分级评价等级',
          value: '',
          fieldName: 'envLevel'
        },
        {
          label: '企业分级评价报告',
          value: '',
          fieldName: 'evaluationReportList',
          type: '分级评价报告',
          isFile: true
        },
        {
          label: '有无生产实体',
          value: '',
          fieldName: 'isProductEntity'
        },
        {
          label: '环保管理人员数量',
          value: '',
          fieldName: 'envPersonCount'
        },
        {
          label: '环境保护管理人',
          value: '',
          fieldName: 'envHead'
        },
        {
          label: '联系电话',
          value: '',
          fieldName: 'envHeadPhone'
        },
        {
          label: '环境管理体系认证',
          value: '',
          fieldName: 'envManageSystemFileList',
          type: '环境管理体系认证',
          isFile: true
        },
        {
          label: '企业环境风险评估报告',
          value: '',
          fieldName: 'envAttachRiskNameList',
          isFile: true,
          type: '企业环境风险评估报告'
        },
        {
          label: '污染类型',
          value: '-',
          fieldName: 'pollutionType'
        },
        {
          label: '是否重点排污单位',
          value: '-',
          fieldName: 'isImportPollutant'
        }
      ],
      descList1: [
        {
          label: '信用评级等级',
          value: '',
          fieldName: 'creditLevel'
        },
        {
          label: '环境信用承诺书',
          value: '',
          fieldName: 'promiseFileList',
          isFile: true,
          type: '环境信用承诺书'
        }
        // {
        //   label: '联系2年无违法失信行为',
        //   value: '',
        //   fieldName: 'headPhone'
        // }
      ],
      descList2: [
        {
          label: '排污许可证编号',
          value: '',
          fieldName: 'licenseNum'
        },
        {
          label: '监管级别',
          value: '',
          fieldName: 'manageLevel'
        },
        {
          label: '发证日期',
          value: '',
          fieldName: 'issueDate'
        },
        {
          label: '证书有效期',
          value: '',
          fieldName: 'effectiveTime'
        }
      ],
      descList3: [
        {
          label: '生活污水总排口数量',
          value: '',
          fieldName: 'headPhone'
        },
        {
          label: '废水总排口梳理',
          value: '',
          fieldName: 'headPhone'
        },
        {
          label: '安装在线监控设备废水排口数量',
          value: '',
          fieldName: 'headPhone'
        },
        {
          label: '雨水排口数量',
          value: '',
          fieldName: 'headPhone'
        },
        {
          label: '安装在线监控设备的涉及一类排污口的数量',
          value: '',
          fieldName: 'headPhone'
        },
        {
          label: '涉及一类污染物排口数量',
          value: '',
          fieldName: 'headPhone'
        }
      ],
      descList4: [
        {
          label: '安装在线监测有组织直排口数量',
          value: '',
          fieldName: 'headPhone'
        },
        {
          label: '废气总排口梳理',
          value: '',
          fieldName: 'headPhone'
        },
        {
          label: '安装在线监测涉及有毒有害污染物有组织直排口数量',
          value: '',
          fieldName: 'headPhone'
        },
        {
          label: '有毒有害污染有组织排口数量',
          value: '',
          fieldName: 'headPhone'
        },
        {
          label: '涉及有毒有害污染物有组织治理排口数量',
          value: '',
          fieldName: 'headPhone'
        },
        {
          label: '安装在线监测有组织治理排口数量',
          value: '',
          fieldName: 'headPhone'
        },
        {
          label: '安装在线监测涉及有毒有害污染物有组织治理排口数量',
          value: '',
          fieldName: 'headPhone'
        }
      ],
      permitData: {
        permitRecordList: []
      }
    }
  },
  computed: {
    /**
     * 监测是否有文件
     * @returns {(function(*, *): (*|string|string))|*}
     */
    getFileUuId() {
      return (list, fieldName) => {
        console.log(list)
        console.log(fieldName)
        if (list && list.length > 0) {
          const item = list.find((v) => {
            return v['attachType'] === fieldName
          })
          return item ? item.attachUuid : ''
        } else {
          return ''
        }
      }
    }
  },
  mounted() {
    this.companyInfoEnvironment()
  },
  methods: {
    handleCheck(item) {
      this.handleDownLoad(item.value.attachUuid)
    },
    // 获取企业详情数据--基本信息
    async companyInfoEnvironment() {
      this.layout.showAreaLoading(['.qyhbxx', '.qyxypj', '.qypwxk'])
      const { status, data } = await companyInfoEnvironment({ companyId: this.companyId })
      if (status === 0 && data) {
        this.descList.forEach((v) => {
          v.value = data[v.fieldName] ?? ''
        })
        this.descList1.forEach((v) => {
          v.value = data[v.fieldName] ?? ''
        })
        this.descList2.forEach((v) => {
          if (data[v.fieldName] || data[v.fieldName] === 0) {
            if (v.fieldName === 'attachListVOS') {
              const info = data['attachListVOS'].find(k => k.attachType === v.label)
              info ? v.value = info : v.value = ''
            } else {
              v.value = data[v.fieldName]
            }
          } else {
            v.value = ''
          }
        })
      }
      this.layout.hideAreaLoading(['.qyhbxx', '.qyxypj', '.qypwxk'])
    }
  }
}
</script>

<style scoped lang="scss"></style>
